/*

Frequency of use: 1 2 3 [4] 5 MEDIUM HIGH

Short:
    Convert one class so that it appears to be another class.

Long:
    In computer programming, the adapter design pattern (often referred to as 
the wrapper pattern or simply a wrapper) translates one interface for a class 
into a compatible interface. An adapter allows classes to work together that 
normally could not because of incompatible interfaces, by providing its 
interface to clients while using the original interface. The adapter translates 
calls to its interface into calls to the original interface, and the amount of 
code necessary to do this is typically small. The adapter is also responsible 
for transforming data into appropriate forms. For instance, if multiple boolean 
values are stored as a single integer but your consumer requires 
a 'true'/'false', the adapter would be responsible for extracting the 
appropriate values from the integer value.

Information sources:
 - http://calumgrant.net/patterns/index.html
 - http://en.wikipedia.org/wiki/Adapter_pattern
 - http://www.dofactory.com/Patterns/Patterns.aspx
*/

#include <iostream>

class RoundPeg
{
public:
	virtual ~RoundPeg() { }
	virtual void do_round() const=0;
};

class SquarePeg
{
public:
	virtual ~SquarePeg() { }
	virtual void do_square() const=0;
};

class RoundHole
{
public:
	void insert(const RoundPeg & peg) const
	{
		peg.do_round();
	}
};

class SquarePegAdapter : public RoundPeg
{
	SquarePeg & square_peg;
public:
	SquarePegAdapter(SquarePeg & peg) : square_peg(peg)
	{
	}
	void do_round() const
	{
		square_peg.do_square();
	}
};

class HelloWorld : public SquarePeg
{
public:
	void do_square() const
	{
		std::cout << "Hello world!" << std::endl;
	}
};

void hello_world(const RoundPeg & peg)
{
	RoundHole().insert(peg);
}

int main()
{
	HelloWorld peg;
	hello_world(SquarePegAdapter(peg));
	return 0;
}

